﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.IO;

//using Microsoft.VisualStudio.TestTools.UnitTesting;

//using Pibby.Core.Rss;
//using Pibby.Core.IntegrationTests.Stubs;


//namespace Pibby.Core.Tests
//{
//    [TestClass]
//    public class RssFeedTests : IntegrationBaseTestFixture
//    {
//        //[TestMethod]
//        //[ExpectedException(typeof(FileNotFoundException))]
//        //public void Load_NonExistentFile_ThrowsException()
//        //{
//        //    RssFeed rss = RssFeed.Load("This file _probably_ does not exist in the filesystem");
//        //}

//        [TestMethod]
//        public void Load_FeedWithHtmlNoDTD_LoadsNoItems()
//        {
//            StringBuilder builder = new StringBuilder ();

//            builder.Append ("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">");
//            builder.Append ("<head>");
//            builder.Append ("<title>Test</title>");
//            builder.Append ("</head>");
//            builder.Append ("<body>");
//            builder.Append ("<h1>Test</h1>");
//            builder.Append ("<p>Hello World");
//            builder.Append ("</p>");
//            builder.Append ("</body>");
//            builder.Append ("</html>");

//            using (TextReader reader = new StringReader (builder.ToString ()))
//            {
//                RssFeed rss = RssFeed.Load(reader);

//                Assert.AreEqual(0, rss.Items.Count, "Should not have any items loaded");
//            }
//        }

//        [TestMethod]
//        [ExpectedException(typeof(System.Xml.XmlException))]
//        public void Load_FeedWithHtmlWithDTD_ThrowsAuthorisationException()
//        {
//            StringBuilder builder = new StringBuilder();

//            // expecting DTD to cause problems...
//            builder.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
//            builder.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">");
//            builder.Append("<head>");
//            builder.Append("<title>Test</title>");
//            builder.Append("</head>");
//            builder.Append("<body>");
//            builder.Append("<h1>Test</h1>");
//            builder.Append("<p>Hello World");
//            builder.Append("</p>");
//            builder.Append("</body>");
//            builder.Append("</html>");

//            using (TextReader tr = new StringReader(builder.ToString()))
//            {
//                RssFeed rss = RssFeed.Load(tr);

//                Assert.Fail("Should not get here");
//            }
//        }

//        [TestMethod]
//        [ExpectedException(typeof(ArgumentNullException))]
//        public void Load_NullTextReader_ThrowsException()
//        {
//            TextReader reader = null;

//            RssFeed rss = RssFeed.Load(reader);
//        }


//        [TestMethod]
//        public void Load_EmptyFeed_ReturnsNoItems()
//        {
//            RssFeedGenerator generator = new RssFeedGenerator(0);

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(DateTime.Today.Year, rss.PublicationDate.Year);
//            Assert.AreEqual(DateTime.Today.DayOfYear, rss.PublicationDate.DayOfYear);
//            Assert.AreEqual(generator.PodcastTitle, rss.Title);
//            Assert.AreEqual(generator.PodcastHomepage, rss.Link.AbsoluteUri);
//            Assert.AreEqual(generator.PodcastDescription, rss.Description);

//            Assert.AreEqual(generator.PodcastTitle + " updated " + DateTime.Today.ToShortDateString(), rss.ToString());
//            Assert.IsNull(rss.Copyright);
//            Assert.IsNull(rss.ImageUrl);
//            //Assert.IsEmpty(rss.Items);
//        }

//        [TestMethod]
//        public void Load_SingleItemInFeed_ReturnsSingleItem()
//        {
//            int year = 2009;
//            int month = 4;
//            int day = 25;

//            DateTime startDate = new DateTime(year, month, day);

//            RssFeedGenerator generator = new RssFeedGenerator(1, startDate);

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(generator.PodcastTitle, rss.Title);
//            Assert.AreEqual(generator.PodcastHomepage, rss.Link.AbsoluteUri);
//            Assert.AreEqual(generator.PodcastDescription, rss.Description);

//            Assert.IsNull(rss.Copyright);
//            Assert.IsNull(rss.ImageUrl);
//            Assert.AreEqual(1, rss.Items.Count);

//            Assert.AreEqual(startDate.Year, rss.Items.OldestDate.Year);
//            Assert.AreEqual(startDate.DayOfYear, rss.Items.OldestDate.DayOfYear);
//            Assert.AreEqual(rss.Items.MostRecentDate.Year, rss.Items.OldestDate.Year);
//            Assert.AreEqual(rss.Items.MostRecentDate.DayOfYear, rss.Items.OldestDate.DayOfYear);

//            Assert.AreEqual(rss.Items[0].Title, rss.Items[0].ToString());
//            Assert.AreEqual(startDate.Year, rss.Items[0].PublicationDate.Year);
//            Assert.AreEqual(startDate.DayOfYear, rss.Items[0].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 1", rss.Items[0].Title);
//            Assert.AreEqual("Description for episode 1 goes here", rss.Items[0].Description);
//            Assert.AreEqual(string.Format ("http://mypodcast.net/{0}/{1}/{2}/episode1/", year, month, day), rss.Items[0].Link);
//            Assert.IsNotNull(rss.Items[0].Enclosure);
//            Assert.AreEqual(1124, rss.Items[0].Enclosure.Length);
//            Assert.AreEqual(EnclosureMimeType.Audio, rss.Items[0].Enclosure.MimeType);
//            Assert.AreEqual ("http://media.mypodcast.net/media/mypodcast/EP_1.mp3 1124 bytes", rss.Items[0].Enclosure.ToString ());
//        }

//        [TestMethod]
//        public void Load_MultipleItems_ReturnsMultipleItems()
//        {
//            RssFeedGenerator generator = new RssFeedGenerator(5);

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(generator.PodcastTitle, rss.Title);
//            Assert.AreEqual(generator.PodcastHomepage, rss.Link.AbsoluteUri);
//            Assert.AreEqual(generator.PodcastDescription, rss.Description);

//            Assert.IsNull(rss.Copyright);
//            Assert.IsNull(rss.ImageUrl);
//            Assert.AreEqual(5, rss.Items.Count);

//            Assert.AreEqual(rss.Items[0].PublicationDate, rss.Items.MostRecentDate);
//            Assert.AreEqual(rss.Items[4].PublicationDate, rss.Items.OldestDate);

//            Assert.AreEqual(DateTime.Today.Year, rss.Items[0].PublicationDate.Year);
//            Assert.AreEqual(DateTime.Today.DayOfYear, rss.Items[0].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 5", rss.Items[0].Title);
//            Assert.AreEqual(DateTime.Today.AddDays(-1).DayOfYear, rss.Items[1].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 4", rss.Items[1].Title);
//            Assert.AreEqual(DateTime.Today.AddDays(-2).DayOfYear, rss.Items[2].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 3", rss.Items[2].Title);
//            Assert.AreEqual(DateTime.Today.AddDays(-3).DayOfYear, rss.Items[3].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 2", rss.Items[3].Title);
//            Assert.AreEqual(DateTime.Today.AddDays(-4).DayOfYear, rss.Items[4].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 1", rss.Items[4].Title);
//        }

//        [TestMethod]
//        public void Load_NonContiguousItems_ReturnsMultipleItems()
//        {
//            RssFeedGenerator generator = new RssFeedGenerator(3);
//            generator.NonContiguousItems = true;

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(generator.PodcastTitle, rss.Title);
//            Assert.AreEqual(generator.PodcastHomepage, rss.Link.AbsoluteUri);
//            Assert.AreEqual(generator.PodcastDescription, rss.Description);

//            Assert.IsNull(rss.Copyright);
//            Assert.IsNull(rss.ImageUrl);
//            Assert.AreEqual(3, rss.Items.Count);

//            Assert.AreEqual(DateTime.Today.Year, rss.Items[0].PublicationDate.Year);
//            Assert.AreEqual(DateTime.Today.DayOfYear, rss.Items[0].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 3", rss.Items[0].Title);
//            Assert.AreEqual(DateTime.Today.AddDays(-1).DayOfYear, rss.Items[1].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 2", rss.Items[1].Title);
//            Assert.AreEqual(DateTime.Today.AddDays(-2).DayOfYear, rss.Items[2].PublicationDate.DayOfYear);
//            Assert.AreEqual("Episode 1", rss.Items[2].Title);
//        }

//        [TestMethod]
//        public void Load_LargeFeed_ReturnsMultipleItems()
//        {
//            const int episodeCount = 720;

//            RssFeedGenerator generator = new RssFeedGenerator(episodeCount);

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(episodeCount, rss.Items.Count);
//            Assert.AreEqual(rss.Items[0].PublicationDate, rss.Items.MostRecentDate);
//            Assert.AreEqual(rss.Items[episodeCount - 1].PublicationDate, rss.Items.OldestDate);
//        }


//        [TestMethod]
//        public void Load_MissingEnclosureType_DefaultsToAudioForMp3Extension()
//        {
//            const int episodeCount = 1;

//            RssFeedGenerator generator = new RssFeedGenerator(episodeCount);

//            generator.OmitEnclosureType = true;

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(episodeCount, rss.Items.Count);
//            Assert.IsTrue(rss.Items[0].Enclosure.Url.AbsolutePath.EndsWith(".mp3"));
//            Assert.AreEqual(EnclosureMimeType.Audio, rss.Items[0].Enclosure.MimeType);
//        }


//        [TestMethod]
//        public void Load_MissingEnclosures_FindsEmbeddedLinks()
//        {
//            const int episodeCount = 5;

//            RssFeedGenerator generator = new RssFeedGenerator(episodeCount);
//            generator.OmitEnclosure = true;

//            RssFeed rss = RssFeed.Load(generator.ContentStream);

//            Assert.AreEqual(episodeCount, rss.Items.Count);
//            Assert.IsTrue(rss.Items[0].Enclosure.Url.AbsolutePath.EndsWith(".mp3"));
//            Assert.AreEqual(EnclosureMimeType.Audio, rss.Items[0].Enclosure.MimeType);
//        }

//    }
//}
